package cn.syc.struck.demo.fragment.dialog;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import cn.syc.struck.demo.R;
import cn.syc.struck.demo.base.BaseDialogFragment;

/**
 * Created by Administrator on 2017/3/21.
 */

public class UpdateDialog extends BaseDialogFragment {
    public static UpdateDialog newInstance() {

        //Bundle args = new Bundle();
        //args.putString("title", title);
        //args.putStringArray("items", items);
        UpdateDialog fragment = new UpdateDialog();
        //fragment.setArguments(args);
        return fragment;
    }

    //private View mRootView;
    private OnClickListener mListener;

    public void setListener(OnClickListener listener) {
        mListener = listener;
    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        //params.gravity = Gravity.BOTTOM;
        params.gravity = Gravity.CENTER;
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(params);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    }

//    @Nullable
//    @Override
//    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
//        initData();
//        mRootView = inflater.inflate(R.layout.dialog_update, container, false);
//        //AnimationUtils.slideToUp(mRootView);
//        return mRootView;
//    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_update;
    }

    @Override
    //public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    protected void afterCreate(Bundle savedInstanceState) {
        //super.onViewCreated(view, savedInstanceState);
        //------------
        //getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);

        mRootView.findViewById(R.id.textView_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        mRootView.findViewById(R.id.textView_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.click(0);
                }
            }
        });

        //TextView titleView = (TextView) view.findViewById(R.id.title);
        //if (TextUtils.isEmpty(mTitle)) {
        //    view.findViewById(R.id.titleLayout).setVisibility(View.GONE);
        //} else {
        //    titleView.setText(mTitle);
        //}
        //
        //
        //Button cancel = (Button) view.findViewById(R.id.cancel);
        //cancel.setOnClickListener(new View.OnClickListener() {
        //    @Override
        //    public void onClick(View v) {
        //        AnimationUtils.slideToDown(mRootView, new AnimationUtils.AnimationListener() {
        //            @Override
        //            public void onFinish() {
        //                dismiss();
        //            }
        //        });
        //    }
        //});
        //-------------------
    }

    private void initData() {
        //mTitle = getArguments().getString("title");
        //items = getArguments().getStringArray("items");
    }

    public interface OnClickListener {
        void click(int position);
    }
}
